
/// <reference path="base/framwork.js" />
/// <reference path="widget/iscroll.js" />
/// <reference path="base/jquery.js" />
/// <reference path="base/transit.js" />

$(document).ready(function () {
    var loadBox = $('aside.loadBox');
    var articleBox = $('article');
    icom.orient(init);

    function init() {
        loadBox.show();
        //iuser.init(userGetted);
        load_handler();
    }

    function userGetted(data) {
        console.log('用户头像：' + data.headimage);
        console.log('用户昵称：' + data.nickname);
        load_handler();
    }

    function load_handler() {
        var loader = new PxLoader();
        loader.addImage('images/common/turn.png');
        //实际加载进度
        loader.addProgressListener(function (e) {
            var per = Math.round(e.completedCount / e.totalCount * 50);
            //loadPer.html(per + '%');
        });
        loader.addCompletionListener(function () {
            init_handler();
            loader = null;
        });
        loader.start();
    }

    function init_handler() {
        monitor_handler();
        $("footer").load("/module/foot.html");

        icom.fadeIn(loadBox, 500);

        var list = $('#daylist'),
            title = $('.tit span'),
            btn = $('.btn_day');

        $.get('webajax/checkday.ashx', function (res) {
            if (res == 1) {
                btn.on('click', function () {
                    DaysPay(this);
                });
            }
            else btn.hide();

        });

        var date = new Date();
        title.text(convert(date.getFullYear() + "-" + (date.getMonth() + 1)));
        $.get('webajax/getday.ashx', function (res) {
            var tmp;
            $(res).each(function (i, item) {
                tmp = '';
                if (parseInt(item.Day) == parseInt(new Date().getDate())) tmp = 'y';
                else if (item.State == true) tmp = 'y';
                list.append("<div id='d" + item.Day + "' class='" + tmp + "' data-val='" + item.Day + "'>" + item.Day + "</div>");
            });
            icom.fadeOut(loadBox, 500);
        }, 'json');


    }

    function monitor_handler() {
        //		imonitor.add({obj:$('a.btnTest'),action:'touchstart',category:'首页',label:'测试按钮'});
    }

    function convert(dateStr) {

        var dict = { "0": "零", "1": "一", "2": "二", "3": "三", "4": "四", "5": "五", "6": "六", "7": "七", "8": "八", "9": "九", "10": "十", "11": "十一", "12": "十二" };
        var date = dateStr.split('-'),
            yy = date[0],
            mm = date[1];
        var yearStr = dict[yy[0]] + dict[yy[1]] + dict[yy[2]] + dict[yy[3]] + '年',
            monthStr = dict['' + Number(mm)] + '月';
        return yearStr + monthStr;
    }

});
